package part1.one;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: shaochong
 * @Date: 2021/8/5
 * @Description:
 */
public class Solution2 {
    public static int[] twoSum(int[] nums, int target) {
        int len = nums.length;
        int[] answer = new int[2];
        Map<Integer, Integer> map = new HashMap();
        for (int i = 0; i < len; i++) {
            int temp =  target - nums[i];
            if (map.get(temp) != null) {
                answer[0] = i;
                answer[1] = map.get(temp);
                break;
            }
            map.put(nums[i], i);
        }
        return answer;
    }


    public static void main(String[] args) {
        int[] arr = new int[4];
        arr[0] = -3;
        arr[1] = 4;
        arr[2] = 3;
        arr[3] = 90;
        int target = 93;
        System.out.println(Arrays.toString(twoSum(arr, target)));
    }


}
